package com.leo;

import javafx.beans.binding.IntegerBinding;
import javafx.beans.property.SimpleIntegerProperty;

/**
 * @ClassName CustomIntegerBindingDemo
 * @Description 自定义绑定
 * @Author wangss
 * @date 2020.06.01 20:54
 * @Version 1.0
 */
public class CustomIntegerBinding extends IntegerBinding {

    private SimpleIntegerProperty x = new SimpleIntegerProperty();

    public CustomIntegerBinding(int value) {
        this.bind(x);
        x.set(value);
    }

    @Override
    protected int computeValue() {
        // 这里可用加公式
        return x.get() * 2;
    }

    public int getX() {
        return x.get();
    }

    public SimpleIntegerProperty xProperty() {
        return x;
    }

    public void setX(int x) {
        this.x.set(x);
    }
}
